
const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  }
}

const users = {
  'admin-token': {
    roles: ['admin'],
    permissions: ['system:user:list', 'system:user:query'],
    message: '操作成功',
    user: {
      deleteStatus: '1',
      deleteBy: '',
      id: '3123',
      username: '1090650726',
      nickname: '测试用户',
      userType: '1',
      email: '1090650726@qq.com',
      phone: '18425642513',
      gender: '1',
      status: '1',
      admin: true
    },
    introduction: 'I am a super administrator',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Super Admin'
  },
  'editor-token': {
    roles: ['editor'],
    introduction: 'I am an editor',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Normal Editor'
  }
}

const menus = [
  {
    name: '系统管理',
    path: '/system',
    redirect: 'noRedirect',
    component: 'Layout',
    alwaysShow: true,
    meta: {
      title: '系统管理',
      icon: 'eye-open'
    },
    children: [{
      name: '用户管理',
      path: 'user',
      component: 'system/user/index',
      meta: {
        title: '用户管理',
        icon: 'user'
      }
    }, {
			name: '存储管理',
			path: 'storage',
			component: 'system/storage/index',
			meta: {
				title: '存储管理',
				icon: 'dashboard'
			}
		}, {
      name: '角色管理',
      path: 'role',
      component: 'system/role/index',
      meta: {
        title: '角色管理',
        icon: 'example'
      }
    }, {
      name: '菜单管理',
      path: 'menu',
      component: 'system/menu/index',
      meta: {
        title: '菜单管理',
        icon: 'el-icon-menu'
      }
    }, {
      name: '字典管理',
      path: 'dict',
      component: 'system/dict/index',
      meta: {
        title: '字典管理',
        icon: 'nested'
      }
    }, {
      name: '公告管理',
      path: 'notice',
      component: 'system/notice/index',
      meta: {
        title: '公告管理',
        icon: 'el-icon-chat-dot-square'
      }
    }, {
			name: '友情链接管理',
			path: '/link',
			component: 'system/link/index',
			meta: {
				title: '友情链接管理',
				icon: 'link'
			}
		}, {
      name: '轮播图管理',
      path: 'carousel',
      component: 'system/carousel/index',
      meta: {
        title: '轮播图管理',
        icon: 'nested'
      }
    }]
  },
  {
    name: '系统监控',
    path: '/monitor',
    redirect: 'noRedirect',
    component: 'Layout',
    alwaysShow: true,
    meta: {
      title: '系统监控',
      icon: 'link'
    },
    children: [{
      name: '数据监控',
      path: 'druid',
      component: 'monitor/druid/index',
      meta: {
        title: '数据监控',
        icon: 'link'
      }
    }, {
      name: '服务监控',
      path: 'server',
      component: 'monitor/server/index',
      meta: {
        title: '服务监控',
        icon: 'link'
      }
    }, {
			name: '系统接口',
			path: 'swagger',
			component: 'monitor/swagger/index',
			meta: {
				title: '系统接口',
				icon: 'table'
			}
		}]
  },
  {
    name: '系统日志',
    path: '/log',
    redirect: 'noRedirect',
    component: 'Layout',
    alwaysShow: true,
    meta: {
      title: '系统日志',
      icon: 'link'
    },
    children: [{
      name: '登录日志',
      path: 'loginLog',
      component: 'log/loginLog/index',
      meta: {
        title: '登录日志',
        icon: 'link'
      }
    }, {
      name: '操作日志',
      path: 'operationLog',
      component: 'log/operationLog/index',
      meta: {
        title: '操作日志',
        icon: 'link'
      }
    }, {
      name: '访问日志',
      path: 'visitLog',
      component: 'log/visitLog/index',
      meta: {
        title: '访问日志',
        icon: 'link'
      }
    }]
  }
]

module.exports = [
  // 登录
  {
    url: '/login',
    type: 'post',
    response: config => {
      const { username } = config.query
      const token = tokens[username]
      // mock error
      if (!token) {
        return {
          code: 5001,
          message: '用户信息不存在.'
        }
      }
      return {
        code: 200,
        data: token
      }
    }
  },

  // 获取用户信息
  {
    url: '/getUserInfo',
    type: 'get',
    response: config => {
      const { token } = config.headers
      const info = users[token]
      // mock error
      if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.'
        }
      }
      return {
        code: 200,
        message: info.message,
        data: {
          permissions: info.permissions,
          roles: info.roles,
          user: info.user
        }
      }
    }
  },

  // 获取菜单
  {
    url: '/getRouters',
    type: 'get',
    response: _ => {
      return {
        code: 200,
        data: menus,
        message: '操作成功'
      }
    }
  },

  // 退出登录
  {
    url: '/logout',
    type: 'post',
    response: _ => {
      return {
        code: 200,
        message: '退出登录成功'
      }
    }
  }
]
